package com.demo.aty;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private Component tvOne;
    private Component tvTwo;
    private Intent intent;
    private Operation build;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initView();
        initData();

    }

    private void initData() {
        tvOne.setClickedListener(this::onClick);
        tvTwo.setClickedListener(this::onClick);
    }

    private void initView() {
        tvOne = findComponentById(ResourceTable.Id_tv_one);
        tvTwo = findComponentById(ResourceTable.Id_tv_two);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_tv_one:
                intent = new Intent();
                build = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.demo.aty")
                        .withAbilityName("com.demo.aty.SimpleGuideView")
                        .build();
                intent.setOperation(build);
                startAbility(intent);
                break;
            case ResourceTable.Id_tv_two:
                intent = new Intent();
                build = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.demo.aty")
                        .withAbilityName("com.demo.aty.ListViewDemo")
                        .build();
                intent.setOperation(build);
                startAbility(intent);
                break;
            default:
                break;

        }
    }
}
